#include "sklcc_api.h"
#include "memop_action.h"
#include "OpenDPI_demo.h"

#include <assert.h>

static u32 memop_is_enough_space(u32 id_space,u32 flow_space);

extern u32 memop_action_start(void *data)
{
	if(data != NULL)
	{
		id_and_flow_struct *id_and_flow = (id_and_flow_struct *)data;
		//check space
		u32 have_enough_space = memop_is_enough_space(id_and_flow->osdpi_id_count,id_and_flow->osdpi_flow_count);
		if(have_enough_space)
		{
			//just smile :)
		}
		else
		{
			assert(id_and_flow->osdpi_ids != NULL);
			assert(id_and_flow->osdpi_flows != NULL);	
			memop_osdpi_ids_free(id_and_flow->osdpi_ids,MAX_OSDPI_IDS);
			id_and_flow->osdpi_id_count = 0;
			memop_osdpi_flows_free(id_and_flow->osdpi_flows,MAX_OSDPI_FLOWS);
			id_and_flow->osdpi_flow_count = 0;

			id_and_flow->osdpi_ids = memop_osdpi_ids_create(MAX_OSDPI_IDS);
			id_and_flow->osdpi_flows = memop_osdpi_flows_create(MAX_OSDPI_FLOWS);
			assert(id_and_flow->osdpi_ids != NULL);
			assert(id_and_flow->osdpi_flows != NULL);	

		}
	}

	return 0;
}


//return 0:have no space
//	else:have enough space
static u32 memop_is_enough_space(u32 id_space,u32 flow_space)
{
	return !((id_space >= MAX_OSDPI_IDS -1 ) || (flow_space >= MAX_OSDPI_FLOWS - 1)); 
}
